import os
import sys

def gbk_to_utf_8(data_dir):
    files = [data_dir + os.sep + f for f in os.listdir(data_dir)]

    for f in files:
        print(os.path.basename(f))
        rf = open(f, "r", encoding="gb18030")
        lines = rf.read()
        rf.close()

        wf = open(f.replace("news_gov_2", "news_gov_2_utf8"), "w", encoding="utf8")
        wf.write(lines)
        wf.close()

if __name__ == "__main__":
    gbk_to_utf_8(sys.argv[1])